<% properties_with_classes(object.all_user_properties).each do |prop| -%>
<%
  # Reject output-only properties because:
  # request: can't specify output-only properties
  # response: output-only values make diffing much harder.
-%>
class <%= prop.property_class[-1] -%>(object):
<% if prop.is_a?(Api::Type::NestedObject) -%>
    def __init__(self, request, module):
        self.module = module
        if request:
            self.request = request
        else:
            self.request = {}

    def to_request(self):
        return remove_nones_from_dict(<%= lines(python_literal(request_properties(prop.properties.reject(&:output), 'self.request', 'self.module'), use_hash_brackets: true)) -%>)

    def from_response(self):
        return remove_nones_from_dict(<%= lines(python_literal(response_properties(prop.properties.reject(&:output), 'self.request', 'self.module'), use_hash_brackets: true)) -%>)
<% elsif prop.is_a?(Api::Type::Array) && prop.item_type.is_a?(Api::Type::NestedObject) -%>
    def __init__(self, request, module):
        self.module = module
        if request:
            self.request = request
        else:
            self.request = []

    def to_request(self):
        items = []
        for item in self.request:
            items.append(self._request_for_item(item))
        return items

    def from_response(self):
        items = []
        for item in self.request:
            items.append(self._response_from_item(item))
        return items

    def _request_for_item(self, item):
        return remove_nones_from_dict(<%= lines(python_literal(request_properties(prop.item_type.properties.reject(&:output), 'item', 'self.module'), use_hash_brackets: true))-%>)

    def _response_from_item(self, item):
        return remove_nones_from_dict(<%= lines(python_literal(response_properties(prop.item_type.properties.reject(&:output), 'item', 'self.module'), use_hash_brackets: true))-%>)
<% end # prop.is_a? NestedObject -%>
<%=
  unless prop == properties_with_classes(object.all_user_properties).last
    "\n" * 2
  end
-%>
<% end -%>
